<?php
namespace app\admin\model;
use think\Model;
use fast\Cols;
class Module extends Model
{
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';

    //多对一
    public function category(){
        return $this->belongsTo('Category','catid','id')->field('id,name,nickname,image');
    }
    //一对多
    public function columns(){
        return $this->hasMany('Column','moduleid');
    }
    //生成建表语句
    public function makesql($name = ''){
        $database = \think\Config::get('database.database');
        $prefix = \think\Config::get('database.prefix');
        //print_r(\think\Config::get('database'));exit;
        $table = $prefix.$name;
        $sql = 'CREATE TABLE `'.$table.'` ('."\n";
        $st = $this->with('columns')->where(['enname'=>$name])->find();
        $columntype = '';
        $carry = $st['columns'];
        $flag = array();
        foreach($carry as $v){
            $flag[] = $v['listorder'];
        }
        array_multisort($flag, SORT_DESC, $carry);
        foreach ($carry as $k => $v) {
            if($v['isintable']==1){
                switch ($v['columntype']) {
                    case 'identity':
                        $columntype = ' bigint(20) unsigned NOT NULL AUTO_INCREMENT ';
                    break;
                    case 'varcharlong':
                        $columntype = ' varchar(1000)  NOT NULL ';
                    break;
                    case 'varcharmid':
                        $columntype = ' varchar(400)  NOT NULL ';
                    break;
                    case 'varcharshort':
                        $columntype = ' varchar(100)  NOT NULL ';
                    break;
                    case 'guid':
                        $columntype = ' varchar(36)  NOT NULL ';
                    break;
                    case 'int':
                        $columntype = ' int(10)  NOT NULL ';
                    break;
                    case 'bigint':
                        $columntype = ' bigint(20)  NOT NULL ';
                    break;
                    case 'smallint':
                        $columntype = ' smallint(4)  NOT NULL ';
                    break;
                    case 'bool':
                        $columntype = ' tinyint(1)  NOT NULL ';
                    break;
                    case 'float':
                        $columntype = ' float(4,2)  NOT NULL ';
                    break;
                    case 'decimal':
                        $columntype = ' decimal(4,2)  NOT NULL ';
                    break;
                    case 'double':
                        $columntype = ' double(18,4)  NOT NULL ';
                    break;
                    case 'image':
                        $columntype = ' varchar(200)  NOT NULL ';
                    break;
                    case 'file':
                        $columntype = ' varchar(200)  NOT NULL ';
                    break;
                    case 'text':
                        $columntype = ' text ';
                    break;
                    case 'text':
                        $columntype = ' enum ';
                    break;
                    default:
                    # code...
                    break;
                }
                $sql .= '`'.$v['columnenname'].'`';
                $sql .= $columntype.' COMMENT \''.$v['columnname'].'\''."\n";
                if($v['columnenname']!='itemid'){
                    if($v['default']){
                        $sql .= '  DEFAULT \''.$v['default'].'\', '."\n";
                    }else{
                        if(($v['columntype']=='int')||($v['columntype']=='bigint')||($v['columntype']=='smallint')||($v['columntype']=='bool')||($v['columntype']=='float')||($v['columntype']=='decimal')||($v['columntype']=='double')){
                            $sql .= '  DEFAULT \'0\', '."\n";
                        }else{
                            $sql .= '  DEFAULT \'\', '."\n";
                        }
                    }
                }else{
                    $sql .= ','."\n";
                }
            }
        }
        $sql .= 'PRIMARY KEY (`itemid`)'."\n";
        $sql .= ') ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT=\'\';';
        db()->execute('DROP TABLE IF EXISTS `'.$table.'`;');
        db()->execute($sql);
        //$pdo->exec($sql);
        //db()->query("SELECT COLUMN_NAME,COLUMN_COMMENT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?", [$table, $database]);
    }

    public function makeaddtemplate($name = ''){
          if($name){
              $ll = Cols::columnread($name);
              $m = $this->get(['enname'=>$name]);
              $lls = array();
              $string = '<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">'."\n";

              foreach ($ll as $k => $v) {
                  if($v['isshowadd']==1){
                    if($v['rname']!=''){
                        $string .= "\t\t".'<input type="hidden" id="c-'.$v['columnenname'].'" name="row['.$v['columnenname'].']" value="{$'.$v['columnenname'].'}" />'."\n";
                        continue;
                    }
                    $string .= "\t\t".'<div class="form-group">'."\n";
                    $string .= "\t\t\t\t".'<label for="c-'.$v['columnenname'].'" class="control-label col-xs-12 col-sm-2">'.$v['columnname'].':</label>'."\n";
                    $string .= "\t\t\t\t".'<div class="col-xs-12 col-sm-8">'."\n";
                    switch ($v['optionform']) {
                      case 'select':
                            $string .= "\t\t\t\t\t\t".'<select id="c-'.$v['columnenname'].'" data-rule="'.$v['columncheck'].'" name="row['.$v['columnenname'].']" '.($v['optionurl']?'dataurl="'.$v['optionurl'].'"':'');
                            $string .= ' class="form-control selectpicker'.($v['optionurl']?'new':'').'">'."\n";
                            if($v['options']){
                                $string .= "\t\t\t\t\t\t\t\t".'<option value="0">请选择</option>';
                                $arr2 = json_decode($v['options'],TRUE);
                                foreach ($arr2 as $kk => $vv) {
                                    $string .= "\t\t\t\t\t\t\t\t".'<option value="'.$kk.'">'.$vv.'</option>'."\n";
                                }
                            }
                            $string .= "\t\t\t\t\t\t".'</select>'."\n";
                      break;
                      case 'radio':
                            $string .= "\t\t\t\t\t\t".'<div class="radio" for="'.$v['columnenname'].'" '.($v['optionurl']?' dataurl="'.$v['optionurl'].'"':'').">\n";
                            if($v['options']){
                                $arr2 = json_decode($v['options'],TRUE);
                                $arr = array();
                                foreach ($arr2 as $kk => $vv) {
                                    $string .= "\t\t\t\t\t\t\t\t".'<label for="'.$v['columnenname'].'"><input name="row['.$v['columnenname'].']" type="radio" value="'.$kk.'" /> '.$vv.'</label>'."\n";
                                }
                            }
                            $string .= "\t\t\t\t\t\t".'</div>'."\n";
                      break;
                      case 'checkbox':
                            $string .= "\t\t\t\t\t\t".'<div class="checkbox" for="'.$v['columnenname'].'" '.($v['optionurl']?' dataurl="'.$v['optionurl'].'"':'').">\n";
                            if($v['options']){
                                $arr2 = json_decode($v['options'],TRUE);
                                $arr = array();
                                foreach ($arr2 as $kk => $vv) {
                                    $string .= "\t\t\t\t\t\t\t\t".'<label for="'.$v['columnenname'].'"><input name="row['.$v['columnenname'].']" type="checkbox" value="'.$kk.'" /> '.$vv.'</label>'."\n";
                                }
                            }
                            $string .= "\t\t\t\t\t\t".'</div>'."\n";
                      break;
                      case 'select3':
                        $string .= "\t\t\t\t\t\t".'<div class="selects3">'."\n";
                            $string .= "\t\t\t\t\t\t\t\t".'<a class="arrow"><img alt="arrowbottom" src="http://qd.andiff.net/netimages/arrow_bottom.png" /></a>'."\n";
                            $string .= "\t\t\t\t\t\t\t\t".'<span class="selected3">请选择</span>';
                            $string .= "\t\t\t\t\t\t\t\t".'<input type="hidden" id="catid" name="row[catid]" value="" />'."\n";
                        $string .= "\t\t\t\t\t\t".'</div>'."\n";
                      break;
                      case 'text':
                        $string .= "\t\t\t\t\t\t".'<div class="form-group">';
                            $string .= "\t\t\t\t\t\t\t\t".'<label for="c-'.$v['columnenname'].'" class="control-label col-xs-12 col-sm-2">'.$v['columnname'].':</label>'."\n";
                            $string .= "\t\t\t\t\t\t\t\t".'<div class="col-xs-12 col-sm-8">';
                                $string .= "\t\t\t\t\t\t\t\t\t\t".'<textarea name="row['.$v['columnenname'].']" id="c-'.$v['columnenname'].'" cols="60" rows="10" class="form-control summernote">{$row.'.$v['columnenname'].'}</textarea>'."\n";
                            $string .= "\t\t\t\t\t\t\t\t".'</div>';
                        $string .= "\t\t\t\t\t\t".'</div>';
                      break;
                      case 'image':
                            $string .= "\t\t\t\t\t\t".'<div class="input-group">'."\n";
                            $string .= "\t\t\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" class="form-control" size="50" name="row['.$v['columnenname'].']" type="text" value="" />'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<div class="input-group-addon no-border no-padding">'."\n";
                                  $string .= "\t\t\t\t\t\t\t\t\t\t".'<span><button type="button" id="plupload-'.$v['columnenname'].'" class="btn btn-danger plupload" data-input-id="c-'.$v['columnenname'].'" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="false" data-preview-id="p-'.$v['columnenname'].'"><i class="fa fa-upload"></i>上传</button></span>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'</div>'."\n";
                            $string .= "\t\t\t\t\t\t\t\t".'<span class="msg-box n-right"></span>'."\n";
                            $string .= "\t\t\t\t\t\t".'</div>'."\n";
                            $string .= "\t\t\t\t\t\t".'<ul class="row list-inline plupload-preview" id="p-'.$v['columnenname'].'"></ul>'."\n";

                      break;
                      case 'file':
                            $string .= "\t\t\t\t\t\t".'<div class="input-group">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" class="form-control" size="50" name="row['.$v['columnenname'].']" type="text" value="" />'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<div class="input-group-addon no-border no-padding">'."\n";
                                    $string .= "\t\t\t\t\t\t\t\t\t\t".'<span><button type="button" id="plupload-'.$v['columnenname'].'" class="btn btn-danger plupload" data-input-id="c-'.$v['columnenname'].'" data-mimetype="application/msword,application/pdf,application/vnd.ms-excel,application/vnd.ms-powerpoint,application/zip" data-multiple="false"><i class="fa fa-upload"></i>上传</button></span>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'</div>'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<span class="msg-box n-right"></span>'."\n";
                            $string .= "\t\t\t\t\t\t".'</div>'."\n";
                      break;
                      case 'datetime':
                            $string .= "\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" data-rule="'.$v['columncheck'].'" class="form-control datetimepicker" name="row['.$v['columnenname'].']" type="text" value="" />'."\n";
                      break;
                      default:
                        if($v['columntype']=='text'){
                            $string .= "\t\t\t\t\t\t".'<textarea name="row['.$v['columnenname'].']" id="c-'.$v['columnenname'].'" cols="60" rows="10" class="form-control summernote"></textarea>'."\n";
                        }else{
                            $string .= "\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" data-rule="'.$v['columncheck'].'" class="form-control" name="row['.$v['columnenname'].']" type="text" value="" />'."\n";
                        }
                      break;
                    }
                    $string .= "\t\t\t\t".'</div>'."\n";
                  $string .= "\t\t".'</div>'."\n";
                }
              }
              $string .= "\t\t\t\t".'<div class="form-group">'."\n";
                  $string .= "\t\t\t\t\t\t".'<label class="control-label col-xs-12 col-sm-2"></label>'."\n";
                  $string .= "\t\t\t\t\t\t".'<div class="col-xs-12 col-sm-8">'."\n";
                  $string .= "\t\t\t\t\t\t\t\t".'<button type="submit" class="btn btn-success btn-embossed">'.__('OK').'</button>'."\n";
                  $string .= "\t\t\t\t\t\t\t\t".'<button type="reset" class="btn btn-default btn-embossed">'.__('Reset').'</button>'."\n";
              $string .= "\t\t\t\t\t\t".'</div>'."\n";
              $string .= "\t\t".'</div>'."\n";
              $string .= '</form>';
              $filename = ADMIN_PATH.DS.'view'.DS.($m['dir']?$m['dir'].DS:'').$name.DS.'add.html';
              $result = file_put_contents($filename, $string);
              if(@$fp = fopen($filename, 'wb')) {
                  flock($fp, LOCK_EX);
                  $len = fwrite($fp, $string);
                  flock($fp, LOCK_UN);
                  fclose($fp);
                  return 1;
              } else {
                  return 0;
              }
          }
    }

    public function makeedittemplate($name = ''){
      if($name){
          $ll = Cols::columnread($name);
          $m = $this->get(['enname'=>$name]);
          $lls = array();
          $string = '<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">'."\n";
          foreach ($ll as $k => $v) {
              if($v['isshowedit']==1){
              $string .= "\t\t".'<div class="form-group">'."\n";
                $string .= "\t\t\t\t".'<label for="c-'.$v['columnenname'].'" class="control-label col-xs-12 col-sm-2">'.$v['columnname'].':</label>'."\n";
                $string .= "\t\t\t\t".'<div class="col-xs-12 col-sm-8">'."\n";
                switch ($v['optionform']) {
                  case 'select':
                    $string .= "\t\t\t\t\t\t".'<select id="c-'.$v['columnenname'].'" data-rule="'.$v['columncheck'].'" name="row['.$v['columnenname'].']" '.($v['optionurl']?'dataurl="'.$v['optionurl'].'"':'');
                    $string .= ' class="form-control selectpicker'.($v['optionurl']?'new':'').'">'."\n";
                    if($v['options']){
                        $string .= '<option value="0">请选择</option>';
                        $arr2 = json_decode($v['options'],TRUE);
                        foreach ($arr2 as $kk => $vv) {
                            $string .= "\t\t\t\t\t\t\t\t".'<option value="'.$kk.'" {if $row.'.$v['columnenname'].' eq \''.$kk.'\'}selected="selected"{/if}>'.$vv.'</option>'."\n";
                        }
                    }
                    $string .= "\t\t\t\t\t\t".'</select>'."\n";
                  break;
                  case 'radio':
                    $string .= "\t\t\t\t\t\t".'<div class="radio" '.($v['optionurl']?'dataurl="'.$v['optionurl'].'"':'').">\n";
                    if($v['options']){
                        $arr2 = json_decode($v['options'],TRUE);
                        foreach ($arr2 as $kk => $vv) {
                            $string .= "\t\t\t\t\t\t\t\t".'<label for="'.$v['columnenname'].'">';
                            $string .= "\t\t\t\t\t\t\t\t".'<input name="row['.$v['columnenname'].']" type="radio" value="'.$kk.'" {if $row.'.$v['columnenname'].' eq \''.$kk.'\'}checked="checked"{/if} /> '.$vv.'</label>'."\n";
                        }
                    }
                    $string .= "\t\t\t\t\t\t".'</div>'."\n";
                  break;
                  case 'checkbox':
                    $string .= "\t\t\t\t\t\t".'<div class="checkbox" '.($v['optionurl']?'dataurl="'.$v['optionurl'].'"':'').">\n";
                    if($v['options']){
                        $arr2 = json_decode($v['options'],TRUE);
                        foreach ($arr2 as $kk => $vv) {
                            $string .= "\t\t\t\t\t\t\t\t".'<label for="'.$v['columnenname'].'">';
                            $string .= "\t\t\t\t\t\t\t\t".'<input name="row['.$v['columnenname'].']" type="checkbox" value="'.$kk.'" {if $row.'.$v['columnenname'].' eq \''.$kk.'\'}checked="checked"{/if} /> '.$vv.'</label>'."\n";
                        }
                    }
                    $string .= "\t\t\t\t\t\t".'</div>'."\n";
                  break;
                  case 'select3':
                    $string .= "\t\t\t\t\t\t".'<div class="selects3">'."\n";
                        $string .= "\t\t\t\t\t\t\t\t".'<a class="arrow"><img alt="arrowbottom" src="http://qd.andiff.net/netimages/arrow_bottom.png" /></a>'."\n";
                        $string .= "\t\t\t\t\t\t\t\t".'<span class="selected3">{$row.category.name}</span>';
                        $string .= "\t\t\t\t\t\t\t\t".'<input type="hidden" id="catid" name="row[catid]" value="{$row.catid}" />'."\n";
                    $string .= "\t\t\t\t\t\t".'</div>'."\n";
                  break;
                  case 'text':
                    $string .= "\t\t\t\t\t\t".'<div class="form-group">';
                        $string .= "\t\t\t\t\t\t\t\t".'<label for="c-'.$v['columnenname'].'" class="control-label col-xs-12 col-sm-2">'.$v['columnname'].':</label>'."\n";
                        $string .= "\t\t\t\t\t\t\t\t".'<div class="col-xs-12 col-sm-8">';
                            $string .= "\t\t\t\t\t\t\t\t\t\t".'<textarea name="row['.$v['columnenname'].']" id="c-'.$v['columnenname'].'" cols="60" rows="10" class="form-control summernote">{$row.'.$v['columnenname'].'}</textarea>'."\n";
                        $string .= "\t\t\t\t\t\t\t\t".'</div>';
                    $string .= "\t\t\t\t\t\t".'</div>';
                  break;
                  case 'image':
                      $string .= "\t\t\t\t\t\t".'<div class="input-group">'."\n";
                        $string .= "\t\t\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" class="form-control" size="50" name="row['.$v['columnenname'].']" type="text" value="{$row.'.$v['columnenname'].'}" />'."\n";
                        $string .= "\t\t\t\t\t\t\t\t".'<div class="input-group-addon no-border no-padding">'."\n";
                        $string .= "\t\t\t\t\t\t\t\t\t\t".'<span><button type="button" id="plupload-'.$v['columnenname'].'" class="btn btn-danger plupload" data-input-id="c-'.$v['columnenname'].'" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="false" data-preview-id="p-'.$v['columnenname'].'"><i class="fa fa-upload"></i>上传</button></span>'."\n";
                        $string .= "\t\t\t\t\t\t\t\t".'</div>'."\n";
                        $string .= "\t\t\t\t\t\t\t\t".'<span class="msg-box n-right"></span>'."\n";
                      $string .= "\t\t\t\t\t\t".'</div>'."\n";
                      $string .= "\t\t\t\t\t\t".'<ul class="row list-inline plupload-preview" id="p-'.$v['columnenname'].'"></ul>'."\n";
                  break;
                  case 'file':
                      $string .= "\t\t\t\t\t\t".'<div class="col-xs-12 col-sm-8">'."\n";
                          $string .= "\t\t\t\t\t\t\t\t".'<div class="input-group">'."\n";
                              $string .= "\t\t\t\t\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" class="form-control" size="50" name="row['.$v['columnenname'].']" type="text" value="{$row.'.$v['columnenname'].'}" />'."\n";
                              $string .= "\t\t\t\t\t\t\t\t\t\t".'<div class="input-group-addon no-border no-padding">'."\n";
                                  $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'<span><button type="button" id="plupload-'.$v['columnenname'].'" class="btn btn-danger plupload" data-input-id="c-'.$v['columnenname'].'" data-mimetype="application/msword,application/pdf,application/vnd.ms-excel,application/vnd.ms-powerpoint,application/zip" data-multiple="false"><i class="fa fa-upload"></i>上传</button></span>'."\n";
                              $string .= "\t\t\t\t\t\t\t\t\t\t".'</div>'."\n";
                              $string .= "\t\t\t\t\t\t\t\t\t\t".'<span class="msg-box n-right"></span>'."\n";
                          $string .= "\t\t\t\t\t\t\t\t".'</div>'."\n";
                      $string .= "\t\t\t\t\t\t".'</div>'."\n";
                  break;
                  case 'datetime':
                      $string .= "\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" data-rule="'.$v['columncheck'].'" class="form-control datetimepicker" name="row['.$v['columnenname'].']" type="text" value="<?php echo \fast\Date::timetodate($row[\''.$v['columnenname'].'\'],5);?>" />'."\n";
                  break;
                  default:
                    if($v['columntype']=='text'){
                        $string .= "\t\t\t\t\t\t".'<textarea name="row['.$v['columnenname'].']" id="c-'.$v['columnenname'].'" cols="60" rows="10" class="form-control summernote">{$row.'.$v['columnenname'].'}</textarea>'."\n";
                    }else{
                        $string .= "\t\t\t\t\t\t".'<input id="c-'.$v['columnenname'].'" data-rule="'.$v['columncheck'].'" class="form-control" name="row['.$v['columnenname'].']" type="text" value="{$row.'.$v['columnenname'].'}" />'."\n";
                    }
                  break;
                }
                $string .= "\t\t\t\t".'</div>'."\n";
              $string .= "\t\t".'</div>'."\n";
            }
          }
          $string .= "\t\t\t\t\t\t".'<div class="form-group">'."\n";
              $string .= "\t\t\t\t\t\t\t\t".'<label class="control-label col-xs-12 col-sm-2"></label>'."\n";
              $string .= "\t\t\t\t\t\t\t\t".'<div class="col-xs-12 col-sm-8">'."\n";
              $string .= "\t\t\t\t\t\t\t\t\t\t".'<button type="submit" class="btn btn-success btn-embossed">'.__('OK').'</button>'."\n";
              $string .= "\t\t\t\t\t\t\t\t\t\t".'<button type="reset" class="btn btn-default btn-embossed">'.__('Reset').'</button>'."\n";
          $string .= "\t\t\t\t\t\t".'</div>'."\n";
          $string .= "\t\t\t\t".'</div>'."\n";
          $string .= '</form>'."\n";

          $filename = ADMIN_PATH.DS.'view'.DS.($m['dir']?$m['dir'].DS:'').$name.DS.'edit.html';
          $result = file_put_contents($filename, $string);
          if(@$fp = fopen($filename, 'wb')) {
              flock($fp, LOCK_EX);
              $len = fwrite($fp, $string);
              flock($fp, LOCK_UN);
              fclose($fp);
              return 1;
          } else {
              return 0;
          }
      }
    }

    public function makelisttemplate($name = ''){
      if($name){
          $ll = Cols::columnread($name);
          $flag = array();
          foreach($ll as $v){
              $flag[] = $v['listorder'];
          }
          array_multisort($flag, SORT_DESC, $ll);
          $m = $this->get(['enname'=>$name]);
          $lls = array();
          $string = '<div class="panel panel-default panel-intro">'."\n";
          $string .= "\t".'<div class="panel-body">'."\n";
          $string .= "\t\t".'<div id="myTabContent" class="tab-content">'."\n";
          $string .= "\t\t\t".'<div class="tab-pane fade active in" id="one">'."\n";
          $string .= "\t\t\t".'<div class="widget-body no-padding">'."\n";
          $string .= "\t\t\t".'<div class="bootstrap-table">'."\n";
          $string .= "\t\t\t\t".'<div class="commonsearch-table">'."\n";
          $string .= "\t\t\t\t\t".'<form class="form-horizontal form-commonsearch" action="" method="get">'."\n";
          $string .= "\t\t\t\t\t".'<fieldset>'."\n";
          $string .= "\t\t\t\t\t".'<div class="row">'."\n";
          foreach ($ll as $k => $v) {
              if(($v['isshowsearch']==1)&&($v['rname']=='')){
                $string .= "\t\t\t\t\t\t".'<div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">'."\n";
                $string .= "\t\t\t\t\t\t".'<label for="'.$v['columnenname'].'" class="control-label col-xs-4">'.$v['columnname'].'</label>'."\n";
                $string .= "\t\t\t\t\t\t".'<div class="col-xs-8">'."\n";
                switch ($v['optionform']) {
                    case 'select':
                        $string .= '<select id="s-'.$v['columnenname'].'" name="search['.$v['columnenname'].']" '.($v['optionurl']?'dataurl="'.$v['optionurl'].'"':'');
                        $string .= ' class="form-control selectpicker'.($v['optionurl']?'new':'').'">'."\n";
                        if($v['options']){
                            $string .= '<option value="0">请选择</option>'."\n";
                            $arr2 = json_decode($v['options'],TRUE);
                            foreach ($arr2 as $kk => $vv) {
                                $string .= "\t\t\t\t\t\t\t\t".'<option value="'.$kk.'" {if isset($'.$v['columnenname'].')}{if $'.$v['columnenname'].' eq \''.$kk.'\'}selected="selected"{/if}{/if}>'.$vv.'</option>'."\n";
                            }
                        }
                        $string .= '</select>'."\n";
                    break;
                    case 'radio':
                        $string .= "\t\t\t\t\t\t".'<div class="radio" '.($v['optionurl']?'dataurl="'.$v['optionurl'].'"':'').">\n";
                        if($v['options']){
                            $arr2 = json_decode($v['options'],TRUE);
                            foreach ($arr2 as $kk => $vv) {
                                $string .= "\t\t\t\t\t\t\t\t".'<label for="'.$v['columnenname'].'">';
                                $string .= "\t\t\t\t\t\t\t\t".'<input name="search['.$v['columnenname'].']" type="radio" value="'.$kk.'" {if $.'.$v['columnenname'].' eq \''.$kk.'\'}checked="checked"{/if} /> '.$vv.'</label>'."\n";
                            }
                        }
                        $string .= "\t\t\t\t\t\t".'</div>'."\n";
                    break;
                    case 'check':
                        $string .= "\t\t\t\t\t\t\t".'<div class="checkbox" '.($v['optionurl']?'dataurl="'.$v['optionurl'].'"':'').">\n";
                        if($v['options']){
                            $arr2 = json_decode($v['options'],TRUE);
                            foreach ($arr2 as $kk => $vv) {
                                $string .= "\t\t\t\t\t\t\t\t".'<label for="'.$v['columnenname'].'">'."\n";
                                $string .= "\t\t\t\t\t\t\t\t".'<input name="search['.$v['columnenname'].']" type="checkbox" value="'.$kk.'" {if $row.'.$v['columnenname'].' eq \''.$kk.'\'}checked="checked"{/if} /> '.$vv.'</label>'."\n";
                            }
                        }
                        $string .= "\t\t\t\t\t\t\t".'</div>'."\n";
                    break;
                    case 'select3':
                      $string .= "\t\t\t\t\t\t\t".'<div class="selects3">'."\n";
                          $string .= "\t\t\t\t\t\t\t\t".'<a class="arrow"><img alt="arrowbottom" src="http://qd.andiff.net/netimages/arrow_bottom.png" /></a>'."\n";
                          $string .= "\t\t\t\t\t\t\t\t".'<span class="selected3">类别名称</span>';
                          $string .= "\t\t\t\t\t\t\t\t".'<input type="hidden" id="catid" name="search[catid]" value="{$catid??\'\'}" />'."\n";
                      $string .= "\t\t\t\t\t\t\t".'</div>'."\n";
                    break;
                    case 'datetime':
                      $string .= "\t\t\t\t\t\t\t".'<input type="text" class="form-control datetimepicker" name="search['.$v['columnenname'].']" value="<?php echo \fast\Date::timetodate($'.$v['columnenname'].',3); ?>" placeholder="'.$v['columnname'].'??\'\'" id="s-'.$v['columnenname'].'" data-index="'.$k.'" />'."\n";
                    break;
                    default:
                      $string .= "\t\t\t\t\t\t\t".'<input type="text" class="form-control" name="search['.$v['columnenname'].']" value="{$'.$v['columnenname'].'??\'\'}" placeholder="'.$v['columnname'].'" id="s-'.$v['columnenname'].'" data-index="'.$k.'" />'."\n";
                      break;
                }
                $string .= "\t\t\t\t\t\t".'</div>'."\n";
                $string .= "\t\t\t\t".'</div>'."\n";
              }
          }

          $string .= "\t\t\t\t\t".'<div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">'."\n";
          $string .= "\t\t\t\t\t\t".'<div class="col-sm-8 col-xs-offset-4 text-center">'."\n";
          foreach ($ll as $k => $v) {
            if(($v['isshowsearch']==1)&&($v['rname']!='')){
                $string .= "\t\t\t\t\t\t".'<input type="hidden" name="search['.$v['columnenname'].']" value="{$'.$v['columnenname'].'??\'\'}" />'."\n";
            }
          }
          $string .= "\t\t\t\t\t\t".'<input type="hidden" name="offset" value="{$offset}" />'."\n";
          $string .= "\t\t\t\t\t\t".'<input type="hidden" name="limit" value="{$limit}" />'."\n";
          $string .= "\t\t\t\t\t\t".'<button type="submit" class="btn btn-success">搜索</button>'."\n";
          $string .= "\t\t\t\t\t\t".'<button type="reset" class="btn btn-default">重置</button>'."\n";
          $string .= "\t\t\t\t\t\t".'</div>'."\n";
          $string .= "\t\t\t\t".'</div>'."\n";
          $string .= "\t\t\t".'</div>'."\n";
          $string .= "\t\t\t".'</fieldset>'."\n";
          $string .= "\t\t".'</form>'."\n";
          $string .= "\t".'</div>'."\n";

          $string .= "\t".'<div class="fixed-table-toolbar">'."\n";
          $string .= "\t\t".'<div class="bs-bars pull-left">'."\n";
          $string .= "\t\t\t".'<div id="toolbar" class="toolbar" style="position: relative;">'."\n";
          $string .= "\t\t\t\t".'<a href="javascript:window.location.reload();" class="btn btn-primary btn-refresh" title="刷新">';
          $string .= "\t\t\t\t".'<i class="fa fa-refresh"></i></a>'."\n";
          $string .= "\t\t\t\t".'<a href="javascript:;" url="'.($m['dir']?$m['dir'].'/':'').$name.'/add';
          if($m['pid']!='0'){
              $sc = '';
              foreach ($ll as $k => $v) {
                  if($v['rname']!=''){
                      $sc = $v['columnenname'];
                  }
              }
              $string .= '?'.$sc.'=<?php echo !empty($'.$sc.')?$'.$sc.':0; ?>&ref=addtabs';
          }
          $string .= '" class="btn btn-success btn-add thisaddtabs" title="添加">';
          $string .= "\t\t\t\t".'<i class="fa fa-plus"></i> 添加</a>'."\n";
          $string .= "\t\t\t\t".'<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled" title="编辑"><i class="fa fa-pencil"></i> 编辑</a>'."\n";
          $string .= "\t\t\t\t".'<a href="javascript:;" class="btn btn-danger btn-del btn-disabled" title="删除"><i class="fa fa-trash"></i>删除</a>'."\n";
          $string .= "\t\t\t\t".'<a href="javascript:;" class="btn btn-danger btn-import" title="导入" id="btn-import-GlaqcJ" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false" initialized="true" style="position: relative; z-index: 1;"><i class="fa fa-upload"></i> 导入</a>'."\n";
          //在有状态status字段的情况下，有状态设置按钮
          if(array_key_exists('Status', $ll)){
              $string .= "\t\t\t\t".'<div class="dropdown btn-group ">'."\n";
              $string .= "\t\t\t\t".'<a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> 设置</a>'."\n";
              $string .= "\t\t\t\t\t".'<ul class="dropdown-menu text-left" role="menu">'."\n";
              if($ll['Status']['options']){
                  $llary = json_decode($ll['Status']['options'],TRUE);
                  foreach ($llary as $kk => $vv) {
                      $string .= "\t\t\t\t\t\t".'<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status='.$kk.'"><i class="fa"></i> '.$vv.'</a></li>'."\n";
                  }
              }
              $string .= "\t\t\t\t\t".'</ul>'."\n";
              $string .= "\t\t\t\t".'</div>'."\n";
          }
          $string .= "\t\t\t".'</div>'."\n";
          $string .= "\t\t".'</div>'."\n";
          $string .= "\t\t".'<div class="columns columns-right btn-group pull-right">'."\n";
          $string .= "\t\t\t".'<button class="btn btn-default" type="button" id="toggleview" name="toggleview" aria-label="toggle" title="切换">'."\n";
          $string .= "\t\t\t\t".'<i class="glyphicon glyphicon-list-alt icon-list-alt"></i>'."\n";
          $string .= "\t\t\t".'</button>'."\n";
          $string .= "\t\t\t".'<div class="keep-open btn-group" title="列">'."\n";
          $string .= "\t\t\t\t".'<button type="button" aria-label="columns" class="btn btn-default dropdown-toggle" data-toggle="dropdown">'."\n";
          $string .= "\t\t\t\t".'<i class="glyphicon glyphicon-th icon-th"></i><span class="caret"></span></button>'."\n";
          $string .= "\t\t\t".'<ul class="dropdown-menu" role="menu">'."\n";
          $string .= "\t\t\t\t\t".'{volist name="columnlist" id="v" key="kk"}'."\n";
  				$string .= "\t\t\t\t\t\t\t".'{if $v.columnenname!=\'itemid\'}'."\n";
  				$string .= "\t\t\t\t\t\t\t\t\t".'<li role="menuitem" class="cheng_showlist"><label>'."\n";
  				$string .= "\t\t\t\t\t\t\t\t\t".'<input type="checkbox" data-field="{$v.columnenname}" value="{$v.itemid}" {if $v.isshowlist==1}checked="checked"{/if} />{$v.columnname}'."\n";
  				$string .= "\t\t\t\t\t\t\t\t\t".'</label></li>'."\n";
  				$string .= "\t\t\t\t\t\t\t".'{/if}'."\n";
  				$string .= "\t\t\t\t\t".'{/volist}'."\n";
          /*
          foreach ($ll as $k => $v) {
              $string .= "\t\t\t\t".'<li role="menuitem" class="cheng_showlist"><label>'."\n";
              $string .= "\t\t\t\t".'<input type="checkbox" data-field="'.$v['columnenname'].'" value="'.$v['itemid'].'" '.($v['isshowlist']?'checked="checked"':'').' />'.$v['columnname']."\n";
              $string .= "\t\t\t\t".'</label></li>'."\n";
              //if($v['isshowlist']==1){}
          }
          */
          $string .= "\t\t\t".'</ul>'."\n";
          $string .= "\t\t".'</div>'."\n";

          $string .= "\t\t".'<div class="export btn-group">'."\n";
          $string .= "\t\t\t".'<button class="btn btn-default dropdown-toggle" aria-label="export type" title="导出数据" data-toggle="dropdown" type="button"><i class="glyphicon glyphicon-export icon-share"></i> <span class="caret"></span></button>'."\n";
          $string .= "\t\t\t".'<ul class="dropdown-menu" role="menu">'."\n";
          $string .= "\t\t\t\t".'<li role="menuitem" data-type="json"><a href="javascript:void(0)">JSON</a></li>'."\n";
          $string .= "\t\t\t\t".'<li role="menuitem" data-type="xml"><a href="javascript:void(0)">XML</a></li>'."\n";
          $string .= "\t\t\t\t".'<li role="menuitem" data-type="csv"><a href="javascript:void(0)">CSV</a></li>'."\n";
          $string .= "\t\t\t\t".'<li role="menuitem" data-type="txt"><a href="javascript:void(0)">TXT</a></li>'."\n";
          $string .= "\t\t\t\t".'<li role="menuitem" data-type="doc"><a href="javascript:void(0)">MS-Word</a></li>'."\n";
          $string .= "\t\t\t\t".'<li role="menuitem" data-type="excel"><a href="javascript:void(0)">MS-Excel</a></li>'."\n";
          $string .= "\t\t\t".'</ul>'."\n";
          $string .= "\t\t\t".'</div>'."\n";
          $string .= "\t\t".'</div>'."\n";

          $string .= "\t".'<div class="fixed-table-container">'."\n";
          $string .= "\t\t".'<div class="fixed-table-body">'."\n";
          $string .= "\t\t".'<table id="table" class="table table-striped table-bordered table-hover" data-operate-edit="1" data-operate-del="1" width="100%">'."\n";
          $string .= "\t\t\t".'<thead>'."\n";
          $string .= "\t\t\t\t".'<tr>'."\n";
          $string .= "\t\t\t\t\t".'<th class="bs-checkbox" data-field="0">'."\n";
          $string .= "\t\t\t\t\t".'<div class="th-inner"><input id="chkSelectAll" name="chkSelectAll" type="checkbox" /></div>'."\n";
          $string .= "\t\t\t\t\t".'<div class="fht-cell"></div>'."\n";
          $string .= "\t\t\t\t\t".'</th>'."\n";
          /*
          foreach ($ll as $k => $v) {
              if(($v['isshowlist']==1)&&($v['columnenname']!='itemid')){
                  $string .= "\t\t\t\t\t".'<th data-field="'.$v['columnenname'].'">'."\n";
                  $string .= "\t\t\t\t\t".'<div class="th-inner">'.$v['columnname'].'</div><div class="fht-cell"></div>'."\n";
                  $string .= "\t\t\t\t\t".'</th>'."\n";
              }
          }
          */
          $string .= "\t\t\t\t\t".'{volist name="columnlist" id="v" key="kk"}'."\n";
					$string .= "\t\t\t\t\t\t\t".'{if condition="($v.isshowlist==1) and ($v.columnenname!=\'itemid\')"}'."\n";
					$string .= "\t\t\t\t\t\t\t\t\t".'<th data-field="{$v.columnenname}">'."\n";
					$string .= "\t\t\t\t\t\t\t\t\t\t\t".'<div class="th-inner">{$v.columnname}</div><div class="fht-cell"></div>'."\n";
					$string .= "\t\t\t\t\t\t\t\t\t".'</th>'."\n";
					$string .= "\t\t\t\t\t\t\t".'{/if}'."\n";
					$string .= "\t\t\t\t\t".'{/volist}'."\n";
          $string .= "\t\t\t\t\t".'<th data-field="operate"><div class="th-inner">操作</div>'."\n";
          $string .= "\t\t\t\t\t".'<div class="fht-cell"></div>'."\n";
          $string .= "\t\t\t\t\t".'</th>'."\n";
          $string .= "\t\t\t\t".'</tr>'."\n";
          $string .= "\t\t\t".'</thead>'."\n";
          $string .= "\t\t\t".'<tbody data-listidx="0" id="datalist">'."\n";
          $string .= "\t\t\t\t".'{volist name="lists" id="vo" key="k"}'."\n";
          $string .= "\t\t\t\t".'<tr data-index="{$k}">'."\n";
          $string .= "\t\t\t\t\t".'<td class="bs-checkbox" columnname="itemid">'."\n";
          $string .= "\t\t\t\t\t".'<input data-index="{$k}" name="btSelectItem" type="checkbox" value="{$vo.itemid}" /></td>'."\n";

          $string .= "\t\t\t\t".'{volist name="columnlist" id="v" key="kk"}'."\n";
          $string .= "\t\t\t\t\t".'{if condition="($v.isshowlist==1) and ($v.columnenname!=\'itemid\')"}'."\n";
          $string .= "\t\t\t\t\t".'<td columnname="{$v.columnenname|ucfirst}">{$vo[$v.columnenname]}'."\n";

          $string .= "\t\t\t\t\t".'</td>'."\n";
          $string .= "\t\t\t\t\t".'{/if}'."\n";
          $string .= "\t\t\t\t".'{/volist}'."\n";
          $string .= "\t\t\t\t\t".'<td columnname="caozuo">'."\n";
          $strs = '';
          $mplist = $this->getModelByPid($m['itemid']);
          foreach ($mplist as $k => $v) {
              $strs .= '<a href="javascript:;" url="';
              $strs .= '/admin/'.($v['dir']?$v['dir'].'/':'').$v['enname'].'/index?dialog=1&amp;';
              $llm = model('Column')->getColumnsByRelation($m['enname']);
              if(count($llm)>0){
                  $strs .= 'search['.$llm[0]['columnenname'].']={$vo.itemid}" class="btn btn-xs btn-primary thisaddtabs" title="查看'.$v['name'].'"><i class="fa fa-cubes"></i>查看'.$v['name'].'</a>&nbsp;';
              }
          }
          //<a href="javascript:;" url="/admin/school/student/index?dialog=1&amp;search[classid]={$vo.itemid}" class="btn btn-xs btn-primary thisaddtabs" title="查看学生"><i class="fa fa-cubes"></i>查看学生</a>
          $string .= "\t\t\t\t\t\t".$strs."\n";
          $string .= "\t\t\t\t\t\t".'<a href="/admin/'.($m['dir']?$m['dir'].'/':'').$name.'/edit?dialog=1&amp;ids={$vo.itemid}" class="btn btn-xs btn-success btn-editone" title="编辑"><i class="fa fa-pencil"></i></a>&nbsp;'."\n";
          $string .= "\t\t\t\t\t\t".'<a href="javascript:;" class="btn btn-xs btn-danger btn-delone" title="{$vo.itemid}"><i class="fa fa-trash"></i></a>'."\n";
          $string .= "\t\t\t\t\t".'</td>'."\n";
          $string .= "\t\t\t\t".'</tr>'."\n";
          $string .= "\t\t\t".'{/volist}'."\n";
          $string .= "\t\t".'</tbody>'."\n";
          $string .= "\t\t".'</table>'."\n";
          $string .= "\t".'</div>'."\n";
          $string .= "\t".'</div>'."\n";
          $string .= "\t\t\t".'<div class="fixed-table-footer" style="display: none;">'."\n";
          $string .= "\t\t\t\t".'<table><tbody><tr></tr></tbody></table>'."\n";
          $string .= "\t\t\t".'</div>'."\n";
          $string .= "\t\t\t".'<div class="fixed-table-pagination" style="display: block;">'."\n";
          $string .= "\t\t\t\t".'<div class="pull-left pagination-detail">'."\n";
          $string .= "\t\t\t\t".'<span class="pagination-info">'."\n";
          $string .= "\t\t\t\t".'显示第 {$offset+1} 到第 {if $totalpage eq $page}{$total}{else}{$limit*$page}{/if} 条记录，总共 {$total} 条记录</span>'."\n";
          $string .= "\t\t\t".'</div>'."\n";
          $string .= "\t\t\t".'<div class="pull-right pagination">'."\n";
          $string .= "\t\t\t\t".'<ul class="pagination">'."\n";
          $string .= "\t\t\t\t".'{if $total <= $limit || $offset eq 0 }'."\n";
          $string .= "\t\t\t\t\t".'<li class="page-pre"><a href="#" class="btn-disabled disabled">上一页</a></li>'."\n";
          $string .= "\t\t\t\t".'{else}'."\n";
          $string .= "\t\t\t\t\t".'<li class="page-pre"><a href="/{$surl}&offset={$offset-$limit}">上一页</a></li>'."\n";
          $string .= "\t\t\t\t".'{/if}'."\n";
          $string .= "\t\t\t\t".'{for start="1" end="($totalpage+1)"}'."\n";
          $string .= "\t\t\t\t\t".'<li class="page-number {if $i eq $page}active{/if}">'."\n";
          $string .= "\t\t\t\t\t".'<a href="{$surl}&offset={$limit*($i-1)}">{$i}</a></li>'."\n";
          $string .= "\t\t\t\t".'{/for}'."\n";
          $string .= "\t\t\t\t".'{if $total <= $limit}'."\n";
          $string .= "\t\t\t\t\t".'<li class="page-next"><a href="/{$surl}&offset={$offset+$limit}">下一页</a></li>'."\n";
          $string .= "\t\t\t\t".'{else}'."\n";
          $string .= "\t\t\t\t\t".'<li class="page-next"><a href="#">下一页</a></li>'."\n";
          $string .= "\t\t\t\t".'{/if}'."\n";
          $string .= "\t\t\t\t".'</ul>'."\n";
          $string .= "\t\t\t".'</div>'."\n";
          $string .= "\t\t".'</div>'."\n";
          $string .= "\t".'</div>'."\n";
          $string .= "\t".'</div><div class="clearfix"></div>'."\n";
          $string .= "\t".'</div>'."\n";
          $string .= "\t".'</div>'."\n";
          $string .= "\t".'</div>'."\n";
          $string .= "\t".'</div>'."\n";
          $string .= "\t".'</div>'."\n";
          $string .= "\t".'</div>'."\n";
          $string .= '<script type="text/javascript">'."\n";
          $string .= 'var pagedata = {'."\n";
          $string .= "\t".'list: {$lists|json_encode},'."\n";
          $string .= "\t".'columns:{$columnlist|json_encode}'."\n";
          $string .= '};'."\n";
          $string .= '</script>'."\n";
          $filename = ADMIN_PATH.DS.'view'.DS.($m['dir']?$m['dir'].DS:'').$name.DS.'index.html';
          $result = file_put_contents($filename, $string);
          if(@$fp = fopen($filename, 'wb')) {
              flock($fp, LOCK_EX);
              $len = fwrite($fp, $string);
              flock($fp, LOCK_UN);
              fclose($fp);
              return 1;
          } else {
              return 0;
          }
      }
    }

    public function makejstemplate($name = ''){
      if($name){
        $ll = Cols::columnread($name);
        $m = $this->get(['enname'=>$name]);
        $lls = array();
        $string = 'define([\'jquery\',\'bootstrap\', \'backend\', \'table\', \'form\',\'upyun\',\'summernote\'], function ($, undefined, Backend, Table, Form,UpYun,Summernote) {'."\n";
        $string .= "\t\t".'var Controller = {'."\n";
        $string .= "\t\t\t\t".'index: function () {'."\n";
        $string .= "\t\t\t\t\t\t".'var table = $("#table");'."\n";
        $string .= "\t\t\t\t\t\t".'$(document).on(\'click\', \'.thisaddtabs\', function (e) {'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'Backend.api.addtabs(Backend.api.replaceids(this, $(this).attr(\'url\')), $(this).attr("title"));'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'return false;'."\n";
        $string .= "\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t".'$(document).on(\'click\',\'.btn-import\',function(e){'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'require([\'upload\'], function (Upload) {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'Upload.api.plupload($(".btn-import", "#toolbar"), function (data, ret) {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$.ajax({'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'type: "post",'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'url: "/admin/'.($m['dir']?$m['dir'].'/'.$name:$name).'/import.html",'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'data: {file: data.url},'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'dataType: \'JSON\','."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'success: function (datak) {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'location.reload();'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'},'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'error: function () {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'alert(\'编辑失败\');'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'},'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'complete: function () {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t".'$(document).on(\'click\', \'#chkSelectAll\', function (e) {'."\n";
        $string .= "\t\t\t\t\t\t".'$(this).prop("checked","checked");'."\n";
        $string .= "\t\t\t\t\t\t".'$("#table input[name=btSelectItem]").each(function(){'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'$(this).prop("checked",!$(this).prop("checked"));'."\n";
        $string .= "\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t".'return false;'."\n";
        $string .= "\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t".'$(document).on(\'click\', \'input[name=btSelectItem]\',function (e) {'."\n";
        $string .= "\t\t\t\t\t\t".'if($("input[name=btSelectItem]:checked").length>0){'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'$(".btn-edit").removeClass(\'disabled\');'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'if(typeof($(".btn-more"))!=\'undefined\'){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$(".btn-more").removeClass(\'disabled\');'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}else{'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$(".btn-edit").addClass(\'disabled\');'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'if(typeof($(".btn-more"))!=\'undefined\'){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$(".btn-more").addClass(\'disabled\');'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t".'$(document).on(\'click\',\'.cheng_showlist input[type=checkbox]\',function(e){'."\n";
				$string .= "\t\t\t\t\t\t".'$.ajax({'."\n";
				$string .= "\t\t\t\t\t\t\t\t".'type: "post",'."\n";
				$string .= "\t\t\t\t\t\t\t\t".'url: "/admin/'.($m['dir']?$m['dir'].'/'.$name:$name).'/showlist.html",'."\n";
				$string .= "\t\t\t\t\t\t\t\t".'data: {ids:$(this).val(),ischeck:$(this).prop(\'checked\')},'."\n";
				$string .= "\t\t\t\t\t\t\t\t".'dataType: \'JSON\','."\n";
				$string .= "\t\t\t\t\t\t\t\t".'success: function (data, status) {'."\n";
				$string .= "\t\t\t\t\t\t\t\t".'},'."\n";
				$string .= "\t\t\t\t\t\t\t\t".'error: function () {'."\n";
				$string .= "\t\t\t\t\t\t\t\t\t\t".'alert(\'编辑失败\');'."\n";
				$string .= "\t\t\t\t\t\t\t\t".'},'."\n";
				$string .= "\t\t\t\t\t\t\t\t".'complete: function () {}'."\n";
				$string .= "\t\t\t\t\t\t".'});'."\n";
				$string .= "\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t".'$(".btn-edit").on("click",function(e){'."\n";
        $string .= "\t\t\t\t\t\t".'e.preventDefault();'."\n";
        $string .= "\t\t\t\t\t\t".'var chenked = $("input[name=\'btSelectItem\']:checked");'."\n";
        $string .= "\t\t\t\t\t\t".'Backend.api.addtabs(Backend.api.replaceids(this, \''.($m['dir']?$m['dir'].'/'.$name:$name).'/edit?ids=\'+chenked[0].value),\'编辑\');'."\n";
        $string .= "\t\t\t\t\t\t".'return false;'."\n";
        $string .= "\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t".'$(".btn-del").on("click",function (e) {'."\n";
        $string .= "\t\t\t\t\t\t".'e.preventDefault();'."\n";
        $string .= "\t\t\t\t\t\t".'var chenked = $("input[name=\'btSelectItem\']:checked");'."\n";
        $string .= "\t\t\t\t\t\t".'var ids = "";'."\n";
        $string .= "\t\t\t\t\t\t".'for(var i=0;i<chenked.length;i++){'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'ids += chenked[i].value+",";'."\n";
        $string .= "\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t".'if(chenked.length==0){'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'var index2 = Layer.confirm(\'请选择字段\',\'请选择\');'."\n";
        $string .= "\t\t\t\t\t\t".'}else{'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'var id = $(this).data("id");'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'var that = this;'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'var index = Layer.confirm('."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'__(\'Are you sure you want to delete this item?\'),'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'{icon: 3, title: __(\'Warning\'), shadeClose: true},'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'function () {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$.ajax({'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'type: "post",'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'url: "/admin/'.($m['dir']?$m['dir'].'/'.$name:$name).'/del.html",'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'data: {ids:ids},'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'dataType: \'JSON\','."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'success: function (data, status) {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'if (status == "success") {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'Layer.close(index);'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'location.reload();'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'},'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'error: function () {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'alert(\'编辑失败\');'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'},'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'complete: function () {}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t".');'."\n";
        $string .= "\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t".'$(".btn-delone").on("click",function(e){'."\n";
        $string .= "\t\t\t\t\t\t".'var ids = $(this).prop("title");'."\n";
        $string .= "\t\t\t\t\t\t".'var index = Layer.confirm('."\n";
        $string .= "\t\t\t\t\t\t\t\t".'__(\'Are you sure you want to delete this item?\'),'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'{icon: 3, title: __(\'Warning\'), shadeClose: true},'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'function () {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$.ajax({'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'type: "post",'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'url: "/admin/'.($m['dir']?$m['dir'].'/'.$name:$name).'/del.html",'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'data: {ids:ids},'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'dataType: \'JSON\','."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'success: function (data, status) {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'if (status == "success") {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'Layer.close(index);location.reload();'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'},'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'error: function () {'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'alert(\'编辑失败\');'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'},'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'complete: function () {}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t".');'."\n";
        $string .= "\t\t\t\t".'});'."\n";

        $string .= "\t\t\t\t".'$(\'div.keep-open ul li[role="menuitem"] input[type="checkbox"]\').on(\'change\', function(e){'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'var cn = $(this).attr("data-field");'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'var cnc = Fast.api.ucfirst(cn);'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'if($(this).is(\':checked\')){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t".'if($("#table thead").is(":hidden")){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t".'addColumnMobile(cn);'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t".'}else{'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t".'addColumnPc(cn);'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}else{'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t".'if($("#table thead").is(":hidden")){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t".'$("#datalist .card-view[columnname="+cn+"]").remove();'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t".'$("#table thead tr th[data-field=\'"+cn+"\']").remove();'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t".'}else{'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t".'//隐藏那个列'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t".'$("#datalist tr td[columnname="+cnc+"]").remove();'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t".'$("#table thead tr th[data-field=\'"+cn+"\']").remove();'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t".'});'."\n";

        $string .= "\t\t\t\t".'//表格切换'."\n";
        $string .= "\t\t\t\t".'$("#toggleview").on(\'click\', function (e) {'."\n";
        $string .= "\t\t\t\t\t\t".'if($("#table thead").is(":hidden")){'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'//转换table视图'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'$("#table thead").show();'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'var ss = \'\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'$("#datalist tr").each(function(i){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'var obj = $(this);'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'ss += \'<tr data-index="\'+i+\'">\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$.each(eval(pagedata.columns),function(k,v){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'if(v.isshowlist==1){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'switch(k.toLowerCase()){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'case \'itemid\':'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<td class="bs-checkbox" columnname="\'+v.columnenname+\'">\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<input data-index="\'+i+\'" name="btSelectItem" type="checkbox" value="\'+obj.find("div.card-view [columnname=\'"+k.toLowerCase()+"\'] input[type=\'checkbox\']").val()+\'" />\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'break;'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'default:'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'var s4 = obj.find("div.card-view[columnname=\'"+v.columnenname+"\'] span.value").html();'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'if(typeof(s4)!=\'undefined\'){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<td columnname="\'+k+\'">\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'ss += s4;'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'</td>\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'ss += \'<td columnname="caozuo">\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'ss += obj.find("div.card-view[columnname=\'caozuo\'] span.value").html();'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'ss += \'</td>\';'."\n";
        $string .= "\t\t\t\t\t\t".'ss += \'</tr>\';'."\n";
        $string .= "\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t".'$("#datalist").html(ss);'."\n";
        $string .= "\t\t".'}else{'."\n";
        $string .= "\t\t\t\t".'//转换cardview视图'."\n";
        $string .= "\t\t\t\t".'$("#table thead").hide();'."\n";
        $string .= "\t\t\t\t".'var ss = \'\';'."\n";
        $string .= "\t\t\t\t".'$("#datalist tr").each(function(i){'."\n";
        $string .= "\t\t\t\t\t\t".'var obj = $(this);'."\n";
        $string .= "\t\t\t\t\t\t".'ss += \'<tr data-index="0">\';'."\n";
        $string .= "\t\t\t\t\t\t".'ss += \'<td>\';'."\n";
        $string .= "\t\t\t\t\t\t".'ss += \'<div class="card-views">\';'."\n";
        $string .= "\t\t\t\t\t\t".'$.each(eval(pagedata.columns),function(k,v){'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'if(v.isshowlist==1){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'ss += \'<div class="card-view" columnname="\'+v.columnenname+\'">\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'switch(k.toLowerCase()){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'case \'itemid\':'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<input data-index="\'+i+\'" name="btSelectItem" type="checkbox" value="\'+obj.find("td[columnname=\'"+k.toLowerCase()+"\'] input[type=\'checkbox\']").val()+\'" />\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'break;'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'default:'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'var s4 = obj.find("td[columnname=\'"+k+"\']").html();'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'if(typeof(s4)!=\'undefined\'){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'ss += \'<span class="title">\'+v.columnname+\'</span><span class="value">\'+s4+\'</span>\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'ss += \'</div>\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t".'ss += \'<div class="card-view" columnname="caozuo">\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'ss += \'<span class="title" style="text-align: center; vertical-align: middle; ">操作</span>\';'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'ss += \'<span class="value">\'+obj.find("td[columnname=\'caozuo\']").html()+\'</span>\';'."\n";
        $string .= "\t\t\t\t\t\t".'ss += \'</div>\';'."\n";
        $string .= "\t\t\t\t\t".'ss += \'</div>\';'."\n";
        $string .= "\t\t\t\t\t".'ss += \'</td>\';'."\n";
        $string .= "\t\t\t\t\t".'ss += \'</tr>\';'."\n";
        $string .= "\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t".'$("#datalist").html(ss);'."\n";
        $string .= "\t\t\t\t".'}'."\n";
        $string .= "\t\t".'});'."\n";

        $string .= "\t\t\t\t".'if($(window).width()<768){'."\n";
      			$string .= "\t\t\t\t\t\t".'$("#toggleview").trigger(\'click\');'."\n";
      	$string .= "\t\t\t\t\t\t".'}'."\n";
      	$string .= "\t\t\t\t".'$(window).resize(function(){'."\n";
      			$string .= "\t\t\t\t\t\t".'if($(window).width()<=768){'."\n";
                $string .= "\t\t\t\t\t\t\t\t".'if(!$("#table thead").is(":hidden")){'."\n";
      					$string .= "\t\t\t\t\t\t\t\t\t\t".'$("#toggleview").trigger(\'click\');'."\n";
                $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
      			$string .= "\t\t\t\t\t\t".'}'."\n";
      			$string .= "\t\t\t\t\t\t".'if($(window).width()>768){'."\n";
                $string .= "\t\t\t\t\t\t\t\t".'if($("#table thead").is(":hidden")){'."\n";
      					$string .= "\t\t\t\t\t\t\t\t\t\t".'$("#toggleview").trigger(\'click\');'."\n";
                $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
      			$string .= "\t\t\t\t\t\t".'}'."\n";
      	$string .= "\t\t\t\t".'});'."\n";
        $string .= "\t\t".'},'."\n";
        $string .= "\t\t\t\t".'add: function () {'."\n";
        $string .= "\t\t\t\t\t\t".'Controller.api.bindevent();'."\n";
        $string .= "\t\t\t\t".'},'."\n";
        $string .= "\t\t\t\t".'edit: function () {'."\n";
        $string .= "\t\t\t\t\t\t".'$(".returnback").click(function(){'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'history.back();'."\n";
        $string .= "\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t".'Controller.api.bindevent();'."\n";
        $string .= "\t\t\t\t".'},'."\n";
        $string .= "\t\t\t\t".'api: {'."\n";
        $string .= "\t\t\t\t\t\t".'bindevent: function () {'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'Form.api.bindevent($("form[role=form]"));'."\n";
        $string .= "\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t".'}'."\n";
        $string .= "\t\t".'};'."\n";
        $string .= "\t\t".'return Controller;'."\n";
        $string .= "\t\t".'});'."\n";

        $string .= 'function creatList(obj, list){'."\n";
        $string .= "\t\t".'$.each(eval(obj), function(i,item) {'."\n";
        $string .= "\t\t\t\t".'var temp = new Object();'."\n";
        $string .= "\t\t\t\t".'temp.text = item.name;'."\n";
        $string .= "\t\t\t\t".'temp.value = item.id;'."\n";
        $string .= "\t\t\t\t".'list.push(temp);'."\n";
        $string .= "\t\t".'});'."\n";
        $string .= '}'."\n";

        $string .= '//补足表格的列(PC)'."\n";
        $string .= 'function addColumnPc(key){'."\n";
        $string .= "\t\t".'var l = 10000;//初始化顺序'."\n";
        $string .= "\t\t".'var columnenname = \'\';var columnname = \'\';'."\n";
        $string .= "\t\t".'$.each(eval(pagedata.columns),function(k,v){'."\n";
        $string .= "\t\t\t\t".'var temp = new Object();'."\n";
        $string .= "\t\t\t\t".'if(k.toLowerCase()==key){'."\n";
        $string .= "\t\t\t\t\t\t".'columnenname = v.columnenname;'."\n";
        $string .= "\t\t\t\t\t\t".'columnname = v.columnname;'."\n";
        $string .= "\t\t\t\t\t\t".'l = v.listorder;'."\n";
        $string .= "\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t".'if((v.listorder>l)&&(v.isshowlist==1)){'."\n";
        $string .= "\t\t\t\t\t\t".'var html = "";'."\n";
        $string .= "\t\t\t\t\t\t".'$("#table thead").find("tr th[data-field=\'"+v.columnenname+"\']").before(\'<th data-field="\'+columnenname+\'"><div class="th-inner">\'+columnname+\'</div><div class="fht-cell"></div></th>\');'."\n";
        $string .= "\t\t\t\t\t\t".'var list = eval(pagedata.list);'."\n";
        $string .= "\t\t\t\t\t\t".'var cv = \'\';'."\n";
        $string .= "\t\t\t\t\t\t".'var lst = $("#table tbody tr").find("td[columnname="+Fast.api.ucfirst(v.columnenname)+"]");'."\n";;
        $string .= "\t\t\t\t\t\t".'//把单元格的列加上'."\n";
        $string .= "\t\t\t\t\t\t".'lst.each(function(i){'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'$(this).before(\'<td columnname="\'+Fast.api.ucfirst(columnenname)+\'">\'+list[i][columnenname.toLowerCase()]+\'</td>\');'."\n";
        $string .= "\t\t\t\t\t\t".'});'."\n";
        $string .= "\t\t\t\t\t\t".'return false;'."\n";
        $string .= "\t\t\t\t".'}'."\n";
        $string .= "\t\t".'});'."\n";
        $string .= '}'."\n";

        $string .= '//补足表格的列(Mobile)'."\n";
        $string .= 'function addColumnMobile(key){'."\n";
        $string .= "\t\t".'var l = 10000;//初始化顺序'."\n";
        $string .= "\t\t".'var columnenname = \'\';var columnname = \'\';'."\n";
        $string .= "\t\t".'$.each(eval(pagedata.columns),function(k,v){'."\n";
        $string .= "\t\t\t\t".'var temp = new Object();'."\n";
        $string .= "\t\t\t\t".'if(k.toLowerCase()==key){'."\n";
        $string .= "\t\t\t\t\t\t".'columnenname = v.columnenname;'."\n";
        $string .= "\t\t\t\t\t\t".'columnname = v.columnname;'."\n";
        $string .= "\t\t\t\t\t\t".'l = v.listorder;'."\n";
        $string .= "\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t".'if((v.listorder>l)&&(v.isshowlist==1)){'."\n";
        $string .= "\t\t\t\t\t\t".'var html = "";'."\n";
        $string .= "\t\t\t\t\t\t".'var list = eval(pagedata.list);'."\n";
        $string .= "\t\t\t\t\t\t".'var cv = \'\';'."\n";
        $string .= "\t\t\t\t\t\t".'var lst = $("#datalist tr td").find("div[columnname="+v.columnenname+"]");'."\n";
        $string .= "\t\t\t\t\t\t".'//把单元格的列加上'."\n";
        $string .= "\t\t\t\t\t\t".'lst.each(function(i){'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'$(this).before(\'<div class="card-view" columnname="\'+columnenname.toLowerCase()+\'"><span class="title">\'+columnname+\'</span><span class="value">\'+list[i][columnenname.toLowerCase()]+\'</span></div>\');'."\n";
        $string .= "\t\t\t\t\t\t".'});return false;'."\n";
        $string .= "\t\t\t\t".'}'."\n";
        $string .= "\t\t".'});'."\n";
        $string .= "\t\t".'return false;'."\n";
        $string .= '}'."\n";
        $string .= '';
        //     });
        // }

        $filename = PUBLIC_PATH.DS.'assets'.DS.'js'.DS.'backend'.DS.($m['dir']?$m['dir'].DS:'').$name.'.js';
        $result = file_put_contents($filename, $string);
        if(@$fp = fopen($filename, 'wb')) {
            flock($fp, LOCK_EX);
            $len = fwrite($fp, $string);
            flock($fp, LOCK_UN);
            fclose($fp);
            return 1;
        } else {
            return 0;
        }

      }
    }
    //生成M层。
    public function makemodelphp($name = ''){
        if($name){
          $ll = Cols::columnread($name);
          $lls = array();
          $string = '<?php'."\n";
          $string .= 'namespace app\admin\model;'."\n";
          $string .= 'use think\Model;'."\n";
          $string .= 'use fast\Cols;'."\n";
          $string .= 'class '.ucfirst($name).' extends Model'."\n";
          $string .= '{'."\n";
          $string .= "\t".'// 开启自动写入时间戳字段'."\n";
          $string .= "\t".'protected $autoWriteTimestamp = \'int\';'."\n";
          $string .= "\t".'// 定义时间戳字段名'."\n";
          $string .= "\t".'protected $createTime = \'createtime\';'."\n";
          $string .= "\t".'protected $updateTime = \'updatetime\';'."\n";
          if(isset($ll['Catid'])){
              $string .= "\t".'//多对一'."\n";
              $string .= "\t".'public function category(){'."\n";
              $string .= "\t\t".'return $this->belongsTo(\'Category\',\'catid\',\'id\')->field(\'id,name,nickname,image\');'."\n";
              $string .= "\t".'}'."\n";
          }
          $mc = model('Column');
          //一对一
          $llst = $mc->getColumnsByRelate($name,1);
          foreach ($llst as $k => $v) {
            $string .= "\t".'public function '.$v['rname'].'(){'."\n";
            $string .= "\t\t".'return $this->hasOne(\''.ucfirst($v['rname']).'\',\''.$v['columnenname'].'\',\'itemid\');'."\n";
            $string .= "\t".'}'."\n";
          }
          //多对一
          $llst = $mc->getColumnsByRelate($name,2);
          foreach ($llst as $k => $v) {
              $string .= "\t".'public function '.$v['rname'].'(){'."\n";
              $string .= "\t\t".'return $this->belongsTo(\''.ucfirst($v['rname']).'\',\''.$v['columnenname'].'\',\'itemid\');'."\n";
              $string .= "\t".'}'."\n";
          }
          //一对多
          $llst = $mc->getColumnsByRelate($name,4);
          foreach ($llst as $k => $v) {
              $string .= "\t".'public function '.$v['cname'].'(){'."\n";
              $string .= "\t\t".'return $this->hasMany(\''.ucfirst($v['cname']).'\',\''.$v['columnenname'].'\',\'itemid\');'."\n";
              $string .= "\t".'}'."\n";
          }
          $string .= "\t".'}'."\n";
          $string .= '?>'."\n";

          $filename = ADMIN_PATH.DS.'model'.DS.ucfirst($name).'.php';
          $result = file_put_contents($filename, $string);
          if(@$fp = fopen($filename, 'wb')) {
              flock($fp, LOCK_EX);
              $len = fwrite($fp, $string);
              flock($fp, LOCK_UN);
              fclose($fp);
              return 1;
          } else {
              return 0;
          }
        }
    }

    public function makecontrollerphp($name = ''){
      if($name){
        $ll = Cols::columnread($name);
        $m = $this->get(['enname'=>$name]);
        $lls = array();
        $string = '<?php'."\n";
        $string .= 'namespace app\admin\controller'.($m['dir']?'\\'.$m['dir']:'').';'."\n";
        $string .= 'use app\common\controller\Backend;'."\n";
        $string .= 'use think\Controller;'."\n";
        $string .= 'use think\Request;'."\n";
        $string .= 'use think\Lang;'."\n";
        $string .= 'use fast\Tree;'."\n";
        $string .= 'use fast\Cols;'."\n";
        $string .= 'use fast\Date;'."\n";
        $string .= 'use think\cache\Driver\File;'."\n";
        $string .= 'class '.ucfirst($name).' extends Backend{'."\n";
        $string .= "\t\t".'protected $model = null;//模型对象'."\n";
        $string .= "\t\t".'protected $columnlist = array();'."\n";
        $string .= "\t\t".'public function _initialize(){'."\n";
        $string .= "\t\t\t\t".'parent::_initialize();'."\n";
        $string .= "\t\t\t\t".'$this->model = model(\''.ucfirst($name).'\');'."\n";
        $string .= "\t\t\t\t".'$this->columnarry = Lang::load(APP_PATH . $this->request->module() . \'/lang/\' . Lang::detect() . \'/module.php\',\'\',1);'."\n";
        $string .= "\t\t".'}'."\n";

        $string .= "\t\t".'public function listforajax(){'."\n";
    				$string .= "\t\t\t\t".'$lst = $this->model->order(\'itemid\',\'desc\')->select();'."\n";
    				$string .= "\t\t\t\t".'print_r(json_encode($lst));'."\n";
    				$string .= "\t\t\t\t".'exit;'."\n";
    		$string .= "\t\t".'}'."\n";

        $string .= "\t\t".'public function add(){'."\n";
        $string .= "\t\t\t\t".'if ($this->request->isPost()){'."\n";
        $string .= "\t\t\t\t\t\t".'$params = $this->request->post("row/a");'."\n";
        $string .= "\t\t\t\t\t\t".'if ($params){'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'$fc = new File();'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'$this->modelValidate = false;'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'if ($this->dataLimit){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$params[$this->dataLimitField] = $this->auth->id;'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'try{'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'//是否采用模型验证'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'if ($this->modelValidate){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$name = basename(str_replace(\'\\\\\', \'/\', get_class($this->model)));'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . \'.add\' : true) : $this->modelValidate;'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$this->model->validate($validate);'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        foreach ($ll as $k => $v) {
            if(($v['columntype']=='int')&&($v['optionform']=='datetime')&&($v['isshowadd']==1)){
                $string .= "\t\t\t\t\t\t\t\t\t\t".'$params[\''.$v['columnenname'].'\'] = Date::datetotime($params[\''.$v['columnenname'].'\']);'."\n";
            }
        }
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$result = $this->model->allowField(true)->save($params);'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'if ($result !== false){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$this->success();'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'}else{'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$this->error($this->model->getError());'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'}'."\n";''."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'catch (\think\exception\PDOException $e){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$this->error($e->getMessage());'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t".'$this->error(__(\'Parameter %s can not be empty\', \'\'));'."\n";
        $string .= "\t\t\t\t".'}else{'."\n";
        foreach ($ll as $k => $v) {
            if($v['rname']!=''){
                $string .= '$'.$v['columnenname'].' = dsafe($this->request->get(\''.$v['columnenname'].'\'));'."\n";
                $string .= '$this->view->assign("'.$v['columnenname'].'",$'.$v['columnenname'].');'."\n";
            }
        }

        $string .= "\t\t\t\t\t\t".'$fc = new File();'."\n";
        $string .= "\t\t\t\t\t\t".'return $this->view->fetch();'."\n";
        $string .= "\t\t\t\t".'}'."\n";
        $string .= "\t\t".'}'."\n";
        $string .= "\t\t"."public function edit(\$ids = NULL){".''."\n";
        //找多对一的关系
        $columnlist = model('Column')->getColumnsByRelate($name,2);
        $st = '';
        foreach ($columnlist as $k => $v) {
            $st .= '->with(\''.$v['rname'].'\')';
        }
        $string .= "\t\t\t\t".'$row = $this->model'.$st.'->find($ids);$fc = new File();'."\n";
        $string .= "\t\t\t\t".'if (!$row){$this->error(__(\'No Results were found\'));}'."\n";
        $string .= "\t\t\t\t".'$adminIds = $this->getDataLimitAdminIds();'."\n";
        $string .= "\t\t\t\t".'if (is_array($adminIds)){'."\n";
        $string .= "\t\t\t\t\t\t".'if (!in_array($row[$this->dataLimitField], $adminIds)){'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'$this->error(__(\'You have no permission\'));'."\n";
        $string .= "\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t".'if ($this->request->isPost()){'."\n";
        $string .= "\t\t\t\t\t\t".'$params = $this->request->post("row/a");'."\n";
        $string .= "\t\t\t\t\t\t".'if ($params){'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'try{'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'//是否采用模型验证'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'if ($this->modelValidate){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$name = basename(str_replace(\'\\\\\', \'/\', get_class($this->model)));'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . \'.edit\' : true) : $this->modelValidate;'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t\t\t".'$row->validate($validate);'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'}'."\n";
        foreach ($ll as $k => $v) {
            if(($v['columntype']=='int')&&($v['optionform']=='datetime')&&($v['isshowedit']==1)){
                $string .= "\t\t\t\t\t\t\t\t\t\t".'$params[\''.$v['columnenname'].'\'] = Date::datetotime($params[\''.$v['columnenname'].'\']);'."\n";
            }
        }
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$result = $row->allowField(true)->save($params);'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'if ($result !== false){$this->success();}'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'else{$this->error($row->getError());}'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'catch (\think\exception\PDOException $e){'."\n";
        $string .= "\t\t\t\t\t\t\t\t\t\t".'$this->error($e->getMessage());'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t".'$this->error(__(\'Parameter %s can not be empty\', \'\'));'."\n";
        $string .= "\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t".'$this->view->assign("row", $row);'."\n";
        $string .= "\t\t\t\t".'return $this->view->fetch();'."\n";
        $string .= "\t\t".'}'."\n";

        $string .= "\t\t".'public function index(){'."\n";
        $string .= "\t\t\t\t".'$columnlist = Cols::columnread(\''.$name.'\');'."\n";
        $string .= "\t\t\t\t".'$flag = array();'."\n";
        $string .= "\t\t\t\t".'foreach($columnlist as $v){'."\n";
        $string .= "\t\t\t\t\t\t".'$flag[] = $v[\'listorder\'];'."\n";
        $string .= "\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t".'array_multisort($flag, SORT_ASC, $columnlist);'."\n";
        $string .= "\t\t\t\t".'//设置过滤方法'."\n";
        $string .= "\t\t\t\t".'$this->request->filter([\'strip_tags\']);'."\n";
        $string .= "\t\t\t\t".'//如果发送的来源是Selectpage，则转发到Selectpage'."\n";
        $string .= "\t\t\t\t".'if ($this->request->request(\'pkey_name\')){'."\n";
        $string .= "\t\t\t\t\t\t".'return $this->selectpage();'."\n";
        $string .= "\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t".'$searchfileds = array();'."\n";
        foreach ($ll as $k => $v) {
            if($v['isshowsearch']==1){
                $string .= "\t\t\t\t".'$searchfileds[\''.$v['columnenname'].'\'] = \''.$v['columntype'].'\';'."\n";
            }
        }
        $string .= "\t\t\t\t".'list($where, $sort, $order, $offset, $limit) = $this->buildparams($searchfileds);'."\n";
        $string .= "\t\t\t\t".'$order = \'desc\';'."\n";
        $string .= "\t\t\t\t".'$sort = \'itemid\';'."\n";
        $string .= "\t\t\t\t".'$total = $this->model'."\n";
        $string .= "\t\t\t\t".'->where($where)'."\n";
        $string .= "\t\t\t\t".'->order($sort, $order)'."\n";
        $string .= "\t\t\t\t".'->count();'."\n";
        $string .= "\t\t\t\t".'$totalpage = 1;$page = 1;'."\n";
        $string .= "\t\t\t\t".'if($limit>0){'."\n";
        $string .= "\t\t\t\t\t\t".'$totalpage = $total%$limit==0?intval($total/$limit):intval($total/$limit)+1;'."\n";
        $string .= "\t\t\t\t\t\t".'//总页数'."\n";
        $string .= "\t\t\t\t\t\t".'if($offset>0){$page = intval($offset/$limit)+1;}'."\n";
        $string .= "\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t".'$list = $this->model'."\n";
        $st = '';
        foreach ($columnlist as $k => $v) {
            $st .= '->with(\''.$v['rname'].'\')';
        }
        if($st){
            $string .= "\t\t\t\t".$st."\n";
        }
        $string .= "\t\t\t\t".'->where($where)'."\n";
        $string .= "\t\t\t\t".'->order($sort, $order)'."\n";
        $string .= "\t\t\t\t".'->limit($offset, $limit)'."\n";
        $string .= "\t\t\t\t".'->select();'."\n";
        $string .= "\t\t\t\t".'for ($i = 0; $i < count($list); $i++) {'."\n";
        $string .= "\t\t\t\t\t\t".'if(isset($list[$i][\'category\'])){'."\n";
        $string .= "\t\t\t\t\t\t\t\t".'$list[$i][\'catname\'] = $list[$i][\'category\'][\'name\'];'."\n";
        $string .= "\t\t\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t\t\t".'unset($list[$i][\'intro\']);unset($list[$i][\'content\']);'."\n";
        foreach ($ll as $k => $v) {
            if(($v['columntype']=='int')&&($v['optionform']=='datetime')&&($v['isshowlist']==1)){
                $string .= "\t\t\t\t\t\t".'$list[$i][\''.$v['columnenname'].'\'] = Date::timetodate($list[$i][\''.$v['columnenname'].'\'],3);'."\n";
            }
            if(($v['optionform']=='select'||$v['optionform']=='checkbox'||$v['optionform']=='radio')&&($v['isshowlist']==1)){
                $string .= "\t\t\t\t\t\t".'if($list[$i][\''.$v['columnenname'].'\']){'."\n";
                    $string .= "\t\t\t\t\t\t\t\t".'$arj = json_decode(\''.$v['options'].'\',true);'."\n";
                    $string .= "\t\t\t\t\t\t\t\t".'$sarj = $arj[$list[$i][\''.$v['columnenname'].'\']];'."\n";
                    $string .= "\t\t\t\t\t\t\t\t".'$list[$i][\''.$v['columnenname'].'\'] = $sarj;'."\n";
                $string .= "\t\t\t\t\t\t".'}'."\n";
            }
        }
        $string .= "\t\t\t\t".'}'."\n";
        $string .= "\t\t\t\t".'$result = array("total" => $total, "rows" => $list);'."\n";
        $string .= "\t\t\t\t".'$this->view->assign("lists",$result[\'rows\']);'."\n";
        $string .= "\t\t\t\t".'$this->view->assign("columnlist",$columnlist);'."\n";
        $string .= "\t\t\t\t".'$this->view->assign("total",$result[\'total\']);'."\n";
        $string .= "\t\t\t\t".'$this->view->assign("offset",$offset);'."\n";
        $string .= "\t\t\t\t".'$this->view->assign("limit",$limit);'."\n";
        $string .= "\t\t\t\t".'$this->view->assign("totalpage",$totalpage);'."\n";
        $string .= "\t\t\t\t".'$this->view->assign("page",$page);'."\n";
        $string .= "\t\t\t\t".'return $this->view->fetch(\'index\');'."\n";
        $string .= "\t\t".'}'."\n";

        $string .= "\t\t".'public function showlist(){'."\n";
        $string .= "\t\t\t\t".'$ids = $this->request->post(\'ids\');'."\n";
        $string .= "\t\t\t\t".'$ischeck = $this->request->post(\'ischeck\');'."\n";
      	$string .= "\t\t\t\t".'model(\'Column\')->where(\'itemid\',$ids)->update([\'isshowlist\'=>($ischeck===\'true\'?1:0)]);'."\n";
      	$string .= "\t\t\t\t".'$ll = model(\'Column\')->getColumnsByModel(\''.$name.'\');'."\n";
      	$string .= "\t\t\t\t".'$lls = array();'."\n";
      	$string .= "\t\t\t\t".'foreach ($ll as $k => $v) {'."\n";
      	$string .= "\t\t\t\t\t\t".'$lls[ucfirst($v[\'columnenname\'])] = $v;'."\n";
      	$string .= "\t\t\t\t".'}'."\n";
      	$string .= "\t\t\t\t".'$string = "<?php return ".var_export($lls, true)."; ?>";'."\n";
      	$string .= "\t\t\t\t".'$filename = COLUMN_PATH.DS.\''.$name.'.php\';'."\n";
      	$string .= "\t\t\t\t".'$result = file_put_contents($filename, $string);'."\n";
      	$string .= "\t\t\t\t".'if(@$fp = fopen($filename,\'wb\')) {'."\n";
      	$string .= "\t\t\t\t\t\t".'flock($fp, LOCK_EX);'."\n";
      	$string .= "\t\t\t\t\t\t".'$len = fwrite($fp, $string);'."\n";
      	$string .= "\t\t\t\t\t\t".'flock($fp, LOCK_UN);'."\n";
      	$string .= "\t\t\t\t\t\t".'fclose($fp);'."\n";
      	$string .= "\t\t\t\t\t\t".'echo $len;exit;'."\n";
      	$string .= "\t\t\t\t".'} else {'."\n";
      	$string .= "\t\t\t\t\t\t".'echo \'失败了\';exit;'."\n";
      	$string .= "\t\t\t\t".'}'."\n";
        $string .= "\t\t".'}'."\n";
        $string .= "}";
        $string .= '?>'."\n";

        $filename = ADMIN_PATH.DS.'controller'.DS.($m['dir']?$m['dir'].DS:'').ucfirst($name).'.php';
        $result = file_put_contents($filename, $string);
        if(@$fp = fopen($filename, 'wb')) {
            flock($fp, LOCK_EX);
            $len = fwrite($fp, $string);
            flock($fp, LOCK_UN);
            fclose($fp);
            return 1;
        } else {
            return 0;
        }
      }
    }

    //得到某个实体的子实体（完全隶属关系）
    public function getModelByPid($pid = 0){
        return $this->where('pid',$pid)->select();
    }

}
?>
